#include <numeric>
#include <vector>
#include <cassert>
#include <iostream>
#include <string>

using namespace std;


void AccumulateTest()
{
	vector<int> iv;
	for(int i = 0; i < 20; i ++)
	{
		iv.push_back(rand());
	}

	int sum1 = 0, sum2 = 0;
	vector<int>::iterator it = iv.begin();
	while(it != iv.end())
		sum1 += *it++;
	
	sum2 = accumulate(iv.begin(), iv.end(), 0);

	assert(sum1 == sum2);
	cout << "sum1 == sum2 == " << sum1 << endl;

	vector<string> strv;
	string resultV, resultIt;
	string srcStr = "// concatenate elements from v and store in sum";
	vector<string>::size_type count = srcStr.size();
	for(int i = 0; i < 20; i ++)
	{
		strv.push_back(srcStr.substr(rand() % count, rand() % count));
	}

	vector<string>::iterator itStrV = strv.begin();
	while(itStrV != strv.end())
	{
		resultV += *itStrV.operator++(0); // *itStrV.operator++() will cause an exception: vector iterator not dereferencable. *itStrV.operator++(0) is okay.

	}

	resultIt = accumulate(strv.begin(), strv.end(), string(""));
	
	assert(resultV == resultIt);
}